package com.unitedvision.service.impl;

import java.util.List;

import javax.annotation.Resource;
import javax.persistence.EntityNotFoundException;

import org.springframework.stereotype.Service;

import com.unitedvision.persistence.domain.GoodsEntity;
import com.unitedvision.persistence.domain.GoodsTypeEntity;
import com.unitedvision.persistence.repository.GoodsRepository;
import com.unitedvision.persistence.repository.GoodsTypeRepository;
import com.unitedvision.service.GoodsService;

@Service
public class GoodsServiceImpl implements GoodsService {

	@Resource
	private GoodsRepository goodsRepository;
	@Resource
	private GoodsTypeRepository goodsTypeRepository;
	
	@Override
	public void save(GoodsEntity goods) {
		goodsRepository.save(goods);
	}

	@Override
	public void delete(GoodsEntity goods) {
		goodsRepository.delete(goods);
	}

	@Override
	public GoodsEntity get(int id) throws EntityNotFoundException {
		return goodsRepository.findOne(id);
	}

	@Override
	public List<GoodsEntity> getAll() throws EntityNotFoundException {
		return goodsRepository.findAll();
	}

	@Override
	public List<GoodsEntity> getByType(GoodsTypeEntity type) {
		return goodsRepository.findByType(type);
	}

	@Override
	public long count() {
		return goodsRepository.count();
	}

	@Override
	public void save(GoodsTypeEntity goodsType) {
		goodsTypeRepository.save(goodsType);
	}

	@Override
	public void delete(GoodsTypeEntity goodsType) {
		goodsTypeRepository.delete(goodsType);
	}

	@Override
	public GoodsTypeEntity getType(int id) throws EntityNotFoundException {
		return goodsTypeRepository.findOne(id);
	}

	@Override
	public List<GoodsTypeEntity> getAllType() throws EntityNotFoundException {
		return goodsTypeRepository.findAll();
	}

	@Override
	public long countType() {
		return goodsTypeRepository.count();
	}
}
